package cn.hnwlgc.controller;

import cn.hnwlgc.pojo.Post;
import cn.hnwlgc.pojo.PostDto;
import cn.hnwlgc.pojo.Result;
import cn.hnwlgc.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/post")
public class PostController {

    @Autowired
    private PostService postService;

    @GetMapping("/list")
    public Result list(){
        List<PostDto> postDtoList=postService.list();
        return Result.success(postDtoList);
    }

    @PostMapping
    public Result save(@RequestBody Post post) {
        postService.add(post);
        return Result.success();
    }
}
